﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input;

namespace MedievalGameProject
{
    public class SoundManager : GameComponent
    {
        public static string OVERWORLD = "Sounds/Music/The Last Confrontation";

        public static string FIGHT = "fight";
        public static string GOT_HIT = "gothit";
        public static string GOT_HIT_2 = "gothit2";
        public static string SHOOT = "shoot";
        public static string SHOOT_2 = "shoot2";
        public static string YOU_LOSE = "youlose";
        public static string YOU_LOSE_2 = "youlose2";
        public static string YOU_WIN = "youwin";

        AudioEngine audioEngine;
        WaveBank waveBank;
        public SoundBank soundBank;
        public Song overworldSong;

        public SoundManager(Game game) : base(game)
        {
            audioEngine = new AudioEngine(@"Content\Sounds\medievalsounds.xgs");

            waveBank = new WaveBank(audioEngine, @"Content\Sounds\Wave Bank.xwb");

            soundBank = new SoundBank(audioEngine, @"Content\Sounds\Sound Bank.xsb");

            overworldSong = Game.Content.Load<Song>(OVERWORLD);

            MediaPlayer.IsRepeating = true;

            MediaPlayer.Volume = 0.65f;
        }

        public override void Initialize()
        {
            base.Initialize();

            PlayMusic(overworldSong);
        }

        public void PlayCue(string cueName)
        {
            soundBank.GetCue(cueName).Play();
        }

        public void PlayMusic(Song song)
        {
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(song);
        }

        public void PlayMusicNoLoop(Song song)
        {
            MediaPlayer.IsRepeating = false;
            MediaPlayer.Play(song);
        }

        public void ResumeMusic()
        {
            MediaPlayer.Resume();
        }

        public void PauseMusic()
        {
            MediaPlayer.Pause();
        }

        public void StopMusic()
        {
            MediaPlayer.Stop();
        }
    }
}
